Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a get_partial_path method to NodePath #78638

Closed
wants to merge 1 commit into from

Conversation

aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Jun 24, 2023

Implements this proposal and closes godotengine/godot-proposals#7148

This PR adds a get_partial_path method to NodePath for getting the first X parts of a path. Discussion: Would it be worth specifying the start index too, or getting the last parts of a path? I only need the first parts for my uses.

I added some test cases to ensure the behavior is correct, and I ran into a minor bug where the internal constructors with the StringName arrays will discard the absolute flag if the path is empty. So I added a check to continue with the construction whenever absolute is set to true (return only when absolute is set to false).

@@ -331,7 +346,7 @@ NodePath NodePath::simplified() const {
}

NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) {
if (p_path.size() == 0) {
if (p_path.size() == 0 && !p_absolute) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this change and the similar one below? Do I need to include a similar change when making the slice method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was an edge case where p_absolute was being ignored if the path was empty.

@aaronfranke
Copy link
Member Author

Superseded by #81822

@aaronfranke aaronfranke closed this Dec 5, 2023
@aaronfranke aaronfranke removed this from the 4.x milestone Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a get_partial_path method to NodePath
3 participants